import axios from "axios";
import { whowloding, hideloding } from './loading'
import store from "@/store";

const ajax = axios.create({
  baseURL: 'http://39.100.95.147:1404',
  // baseURL: 'http://10.31.169.66:1404',
})
// 添加请求拦截器
ajax.interceptors.request.use(function (config) {
  whowloding  
  config.headers.token= store.state.current.token
  return config;
}, function (error) {
  //     // Do something with request error
  return Promise.reject(error);
});


ajax.interceptors.response.use((response) => {
  hideloding
  return response
}, function ({ response }) {
  if (!response) {
    alert("服务器无响应")
  } else {
    switch (response.status) {
      case 404:
        alert("访问资源不存在");
        break;
      case 500:
        alert("服务器内部错误");
        break;
      default:
        alert("访问出错")
    }
  }
})


export default ajax;